#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
using namespace std;
#include <vector>
#include <string>
#include <algorithm>
class Solution {
public:
    vector<vector<int>> threeSum(vector<int>& nums) {
        sort(nums.begin(), nums.end());
        vector<vector<int>> vv;
        for (int sz = nums.size() - 1; sz > 1; sz--)
        {
            int left = 0;
            int right = sz - 1;
            int max = nums[sz];
            while (left < right)
            {
                int sum = nums[left] + nums[right] + max;
                if (sum < 0)
                {
                    left++;
                }
                else if (sum == 0)
                {
                    if (vv.empty())
                        vv.push_back({ nums[left],nums[right],max });
                    else if (vv[vv.size() - 1][0] != nums[left]
                        || vv[vv.size() - 1][1] != nums[right]
                        || vv[vv.size() - 1][2] != max)
                        vv.push_back({ nums[left],nums[right],max });
                    break;
                }
                else
                {
                    right--;
                }
            }
        }

        return vv;
    }
};

int main()
{

    Solution p;
    vector<int> arr = { -1,0,1,2,-1,-4,-2,-3,3,0,4 };
    p.threeSum(arr);
    return 0;
}